package me.xiaoyan.ehr.cron;

import me.xiaoyan.ehr.service.VerifyTokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class ProcessVerifyToken {

    private VerifyTokenService verifyTokenService;

    @Autowired
    public void setVerifyTokenService(VerifyTokenService verifyTokenService) {
        this.verifyTokenService = verifyTokenService;
    }

    @Scheduled(cron = "0 0 0 * * ?")
    public void scheduledTask() {
        System.out.println("开始删除已经失效的token：" + LocalDateTime.now());
        try {
            verifyTokenService.deleteAllExpireToken();
            System.out.println("成功删除已经失效的token：" + LocalDateTime.now());
        } catch (Exception e) {
            System.out.println(e.getMessage());
            System.out.println("删除已经失效的token失败了，" + LocalDateTime.now());
        }
    }
}
